<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a><cite>运维管理</cite></a>
    <a><cite>网站设置</cite></a>
  </div>
</div>

<script type="text/html" template lay-url="agent-admin/settings" lay-done="layui.data.done(d.data)">
  <div class="layui-fluid layui-form">
    <div class="layui-form">
      {{# var settings = d.data }}
      <div class="layui-card">
        <div class="layui-card-header">
          基本信息
        </div>
        <div class="layui-card-body">
          <div class="layui-form-item">
            <label class="layui-form-label form-required">网站名称</label>
            <div class="layui-input-inline">
              <input type="text" lay-verify="required" class="layui-input" autocomplete="off"
                     name="website_name" value="{{settings.website_name || ''}}">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label form-required">网站图标</label>
            <div class="layui-input-block">
              <div id="logo_image"></div>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">开启转售</label>
            <div class="layui-input-inline">
              <input type="checkbox" name="enable_resale" lay-skin="switch" lay-text="是|否"
                     {{settings.website_enable_resale==1?'checked':''}}>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">开启合成</label>
            <div class="layui-input-inline">
              <input type="checkbox" name="enable_convert" lay-skin="switch" lay-text="是|否"
                     {{settings.website_enable_convert==1?'checked':''}}>
            </div>
          </div>

        </div>
      </div>

      <div class="layui-card">
        <div class="layui-card-header">
          交易所
        </div>
        <div class="layui-card-body">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">显示交易所入口</label>
            <div class="layui-input-inline">
              <input type="checkbox" name="enable_exchange" lay-skin="switch" lay-text="是|否"
                     {{settings.website_enable_exchange==1?'checked':''}}>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">交易所入口链接</label>
            <div class="layui-input-inline" style="width: 500px">
              <input type="text" class="layui-input" name="hezhi_url" value="{{settings.hezhi_url || ''}}"
                     autocomplete="off">
            </div>
          </div>
        </div>
      </div>
      <div class="layui-card">
        <div class="layui-card-header">
          隐私政策
        </div>
        <div class="layui-card-body">
          <div class="layui-form-item">
            <div id="privacy">
              {{settings.website_privacy || ''}}
            </div>
          </div>
        </div>
      </div>
      <div class="layui-card">
        <div class="layui-card-header">
          服务协议
        </div>
        <div class="layui-card-body">
          <div class="layui-form-item">
            <div id="agreement">
              {{settings.website_agreement || ''}}
            </div>
          </div>
        </div>
      </div>

      <div class="layui-card">
        <div class="layui-card-header">
          关于我们
        </div>
        <div class="layui-card-body">
          <div class="layui-form-item">
            <div id="aboutus">
              {{settings.website_aboutus || ''}}
            </div>
          </div>
        </div>
      </div>

      <div class="layui-card">
        <div style="margin-bottom: 60px"></div>
        <div class="layui-form-item">
          <div class="layui-footer">
            <div class="layui-input-block">
              <input type="button" lay-submit lay-filter="submit_settings" value="保存"
                     class="layui-btn">
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</script>
<script>
  layui.data.done = function (obj) {
    layui.use(['wangEditor', 'fox_upload'], function () {
      let form = layui.form
        , admin = layui.admin
        , editor = layui.wangEditor
        , fox_upload = layui.fox_upload

      form.render()

      //编辑器
      editor.render({
        elem: "#privacy"
        , height: 500
        , name: 'website_privacy'
        , url: 'editor/images'
      });
      editor.render({
        elem: "#agreement"
        , height: 500
        , name: 'website_agreement'
        , url: 'editor/images'
      });
      editor.render({
        elem: "#aboutus"
        , height: 500
        , name: 'website_aboutus'
        , url: 'editor/images'
      });

      //上传控件初始化
      fox_upload.render({
        elem: '#logo_image'
        , url: 'agent-admin/settings/website_logo'
        , headers: {
          Authorization: admin.getAccessToken('Bearer')
        }
        , value: obj.website_logo
        , text: '点击上传'
        , name: 'website_logo'
      })

      // 提交
      form.on('submit(submit_settings)', function (data) {
        let field = data.field;
        field.website_enable_resale = field.enable_resale === 'on' ? 1 : 0
        field.website_enable_convert = field.enable_convert === 'on' ? 1 : 0
        field.website_enable_exchange = field.enable_exchange === 'on' ? 1 : 0
        admin.post('agent-admin/settings', field, function () {
          layer.msg('保存成功', {
            offset: '15px'
            , icon: 1
            , time: 1000
          });
        });
      });
    });
  }
</script>
